package com.zhb.cms.domain.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.zhb.cms.domain.service.UserLoginService;
import com.zhb.cms.domain.vo.UserLoginVO;
import com.zhb.cms.domain.vo.UserTokenVO;
import com.zhb.cms.sdk.aop.InterfaceApiLabel;
import com.zhb.cms.sdk.bean.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("cms/user")
@Api(description="用户领域登录资源服务")
public class UserLoginController {
	@Autowired
	private UserLoginService userLoginService;
	/**
	 * 
	* @Title: login 
	* @Description: 用户通用登录服务 
	* @author  张海滨  zhanghb22 
	* @date 2017年12月14日 下午3:04:46 
	* @return Result<UserTokenVO>    返回类型
	 */
	@ApiOperation(value = "userlogin001-用户通用登录服务", notes = "用户通用登录服务接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "Zhb_Authen_Token", value = "令牌", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Business_Serialid", value = "交易流水", required = true, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Portal_Code", value = "请求方门户编码", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Menu_Code", value = "请求方菜单编码", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Node_Ip", value = "请求方节点IP", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_Type", value = "客户端设备类型编码:参见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_Hostname", value = "客户端设备名", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_OsType", value = "客户端设备系统类型编码:见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_OsVersion", value = "客户端设备系统版本信息", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_BsType", value = "客户端设备浏览器类型编码:见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_BsVersion", value = "客户端设备浏览器版本信息", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Accept", value = "接收属性", required = true, dataType = "String", paramType = "header", defaultValue = "application/json"),
			@ApiImplicitParam(name = "Accept-Charset", value = "接收字符集", required = true, dataType = "String", paramType = "header", defaultValue = "utf-8"),
			@ApiImplicitParam(name = "Content-Type", value = "内容类型", required = true, dataType = "String", paramType = "header", defaultValue = "application/json; charset=UTF-8") })
	@RequestMapping(value = "/login", method = RequestMethod.POST,produces="application/json;charset=UTF-8")
	@InterfaceApiLabel(value = "userlogin001",description="用户登录通用服务接口")
	public Result<UserTokenVO> login(@RequestBody UserLoginVO userLoginVO,@RequestHeader HttpHeaders headers){
		Result<UserTokenVO> login = userLoginService.login(userLoginVO);
		return login;		
	}
	@ApiOperation(value = "userlogin002-用户登出服务", notes = "用户登出服务接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "Zhb_Authen_Token", value = "令牌", required = true, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Business_Serialid", value = "交易流水", required = true, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Portal_Code", value = "请求方门户编码", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Menu_Code", value = "请求方菜单编码", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Node_Ip", value = "请求方节点IP", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_Type", value = "客户端设备类型编码:参见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_Hostname", value = "客户端设备名", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_OsType", value = "客户端设备系统类型编码:见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_OsVersion", value = "客户端设备系统版本信息", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_BsType", value = "客户端设备浏览器类型编码:见主数据", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Zhb_Request_Equip_BsVersion", value = "客户端设备浏览器版本信息", required = false, dataType = "String", paramType = "header"),
			@ApiImplicitParam(name = "Accept", value = "接收属性", required = true, dataType = "String", paramType = "header", defaultValue = "application/json"),
			@ApiImplicitParam(name = "Accept-Charset", value = "接收字符集", required = true, dataType = "String", paramType = "header", defaultValue = "utf-8"),
			@ApiImplicitParam(name = "Content-Type", value = "内容类型", required = true, dataType = "String", paramType = "header", defaultValue = "application/json; charset=UTF-8") })
	@RequestMapping(value = "/loginOut", method = RequestMethod.DELETE,produces="application/json;charset=UTF-8")
	@InterfaceApiLabel(value = "userlogin001",description="用户登录通用服务接口")
	public Result<String> loginOut(@RequestHeader HttpHeaders headers){
		String token=headers.getFirst("Zhb_Authen_Token");
		Result<String> loginOut = userLoginService.loginOut(token);
		return loginOut;		
	}
	
}
